#!/usr/bin python
from plugins.config.config_package import *

keywords = [
    'CheckVul Success','CheckVul Failed','Server Connection Timeout'
]

class Jbosscan(object):
    def jboss_scan(url):
        try:
            header = {
            	"User-Agent":"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0"
            }

            vuldirs=['jmx-console','web-console','invoker/JMXInvokerServlet','admin-console','jbossmq-httpil/HTTPServerILServlet','invoker/readonly']
            for dirs in vuldirs:
                dir = dirs.strip()
                turl = url + dir
                res = requests.get(turl,headers=header,verify=False,timeout=2)
                if res.status_code == 401:
                    if 'Not Found' not in res.text and 'jmx' in turl:
                        print("[+] Jboss jmx-console {}\n".format(keywords[0]) + " URL: {}\n".format(turl))
                        
                    elif 'Not Found' not in res.text and "web" in turl:
                        print("[+] Jboss Web-console {}\n".format(keywords[0]) + " URL: {}\n".format(turl))
                        
                    else:
                        pass
                else:
                    pass
                if res.status_code == 200:
                    if 'Not Found' not in res.text and "admin" in turl:
                        print("[+] Jboss Admin-console {}\n".format(keywords[0]) + " URL: {}\n".format(turl))
                        
                    elif 'Not Found' not in res.text and "web" in turl:
                        print("[+] JBoss JMXInvokerServlet(CVE-2015-7501) {}\n".format(keywords[0]) + " URL: {}\n".format(turl))
                        
                    else:
                        pass
                else:
                    pass
                if res.status_code == 500:
                    if res.status_code == 500:
                        if 'Not Found' not in res.text and "readonly" in turl:
                            print("[+] JBoss CVE-2017-12149 {}".format(keywords[0]) + " URL: {}\n".format(turl))
                            
                        else:
                            pass
                    else:
                        pass
        except Exception as e:
            pass
        except KeyboardInterrupt:
            sys.exit()